/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.model;

import com.common.json.EventLibraryJson;
import com.employee.controller.EventLibraryBeanRemote;
import com.entities.EventLibrary;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author NguyenVan
 */
public class EventLibraryModel {

    public EventLibraryModel() {
    }

    private EventLibraryBeanRemote Remote() {
        try {
            InitialContext ict = new InitialContext();
            EventLibraryBeanRemote remote = (EventLibraryBeanRemote) ict.lookup("java:global/BluePumpkinEJB/EventLibraryBean!com.employee.controller.EventLibraryBeanRemote");
            return remote;
        } catch (NamingException ex) {
            Logger.getLogger(EventLibraryModel.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    public List<EventLibrary> ListEventLibrary() {
        List<EventLibrary> list = new ArrayList<EventLibrary>();
        List<String> listJson = Remote().ListEventLibrary();
        for (String json : listJson) {
            EventLibrary el = EventLibraryJson.convertJSONObjectStringToEventLibraryForFillEventsDataTable(json);
            list.add(el);
        }
        return list;

    }

    public EventLibrary getEventLibraryDetailsById(int id) {
        String object;
        object = Remote().getEventLibraryDetailsById(id);
        EventLibrary ev = EventLibraryJson.convertJSONObjectStringToEventLibraryForFillEventsDataTable(object);
        return ev;
    }

}
